package com.android.publicModule.webview;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.publicModule.system.SystemInfo;
import com.android.publicModule.tools.Tools;
import com.android.publicModule.webview.info.UrlInfo;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.OnHierarchyChangeListener;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.JavascriptInterface;
import android.widget.ZoomButtonsController;


public class WebViewManage {
	
	private Context mContext;
	private Activity mActivity;
	private ArrayList<UrlInfo> urlInfoList;
	private MugeWebView mWebView;
	private WebSettings mWebSettings;
	private OnLoadProgressListener loadProgressListener;
	private static final String DEFAULT_URL_BLANK = "about:blank";
	private String defaultData,defaultMimeType="text/html",defaultEncoding="UTF-8";
	
	public WebViewManage() {
		
	}
	
	public WebViewManage(Activity activity) {
		setActivity(activity);
		setMugeWebView(new MugeWebView(activity));
	}
	
	public void setMugeWebView(MugeWebView webView) {
		mWebView = webView;
		mWebSettings = mWebView.getSettings();
	}
	
	/**
	 * 绑定WebView 所在的Activity
	 * @param activity
	 */
	public void setActivity(Activity activity) {
		mContext = activity.getApplicationContext();
		mActivity = activity;
	}
	
	/**
	 * 默认初始化WebView及相关设置
	 */
	public void initDefaultWeb() {
		initDefaultWebView();
		initDefaultWebSettings();
	}
	
	/**
	 * 资源释放
	 */
	public void unInit() {
		if(urlInfoList!=null)
		{
			if(urlInfoList.size()>0)
			{
				urlInfoList.clear();
			}
			urlInfoList = null;
		}
		if(loadProgressListener!=null)
		{
			loadProgressListener=null;
		}
		defaultData = null;
		mWebSettings = null;
		if(mWebView!=null)
		{
			mWebView.freeMemory();
			mWebView.destroy();
		}
		mWebView = null;
		mActivity = null;
		mContext = null;
	}
	
	public void initDefaultWebSettings() {
		
		mWebSettings.setJavaScriptEnabled(true);
		mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
		mWebSettings.setPluginsEnabled(true);
		mWebSettings.setPluginState(PluginState.ON);
		
		mWebSettings.setSupportZoom(true);
		mWebSettings.setBuiltInZoomControls(true);
		mWebSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
		mWebSettings.setSupportMultipleWindows(true);
		
		mWebSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); 
		mWebSettings.setUseWideViewPort(true);
		
		mWebSettings.setAppCacheEnabled(false);
		mWebSettings.setLightTouchEnabled(true);
		
		mWebSettings.setSaveFormData(true);
		mWebSettings.setSavePassword(true);
		mWebSettings.setDefaultFixedFontSize(16);
		mWebSettings.setDefaultFontSize(16);
		
		mWebSettings.setAllowFileAccess(true);
		mWebSettings.setDomStorageEnabled(true);
		
        //webSettings.setLoadsImagesAutomatically(true);
        //webSettings.setBlockNetworkImage(true);
        
        //支持缩放
        if (android.os.Build.VERSION.SDK_INT > 10) {
            try {
            	mWebSettings.setDisplayZoomControls(false);
            } catch(NoSuchMethodError e) {
                
            }
        }
        
        mWebSettings.setAppCacheEnabled(true);
        mWebSettings.setLoadWithOverviewMode(true);
        mWebSettings.setDefaultTextEncodingName(defaultEncoding);
	}
	
	public void initDefaultWebView() {
		mWebView.setWebChromeClient(defaultWebChromeClient);
		mWebView.setWebViewClient(defaultWebViewClient);
		
		mWebView.setOnKeyListener(defaultOnKeyListener);
		mWebView.setOnClickListener(defaultOnClickListener);
		mWebView.setOnLongClickListener(defaultOnLongClickListener);
		
		mWebView.setOnCreateContextMenuListener(defaultOnCreateContextMenuListener);
		mWebView.setOnFocusChangeListener(defaultOnFocusChangeListener);
		mWebView.setOnHierarchyChangeListener(defaultOnHierarchyChangeListener);
		mWebView.setOnTouchListener(defaultOnTouchListener);

        if (android.os.Build.VERSION.SDK_INT <= 10) {
        	setZoomControlGone(mWebView);
        }
        
        mWebView.setInitialScale(-1);
        
        mWebView.setBackgroundColor(0x00000000);
        
        mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        
        mWebView.setOnScrollChangeListener(defaultOnScrollChangedListener);
        
        mWebView.addJavascriptInterface(defaultJavascriptInterface, "muge");
	}
	
	/**
	 * 获取WebView实例
	 * @return
	 */
	public MugeWebView getWebView() {
		return mWebView;
	}
	
	/**
	 * 获取WebView的当前设置WebSettings
	 * @return
	 */
	public WebSettings getSettings() {
		return mWebSettings;
	}
	
	private String getHeadersJSONArray(Map<String, String> headers){
		String headersJsonArr = null;
		if(headers!=null)
		{
			Set<Entry<String, String>> setList = headers.entrySet();
			if(setList!=null&&setList.size()>0)
			{
				Entry<String, String> entry;
				Iterator<Entry<String, String>> iterator = setList.iterator();
				if(iterator!=null)
				{
					JSONArray jsonArr = new JSONArray();
					JSONObject jsonObj;
					while(iterator.hasNext())
					{
						entry = iterator.next();
						if(entry!=null)
						{
							jsonObj = new JSONObject();
							try {
								jsonObj.put("name", entry.getKey());
								jsonObj.put("value", entry.getValue());
							} catch (JSONException e) {
							}
							jsonArr.put(jsonObj);
						}
					}
					headersJsonArr = jsonArr.toString();
				}
			}
		}
		return headersJsonArr;
	}
	
	private Map<String, String> getHeadersMap(String headersJsonArr) {
		Map<String, String> headers = null;
		JSONArray jsonArr = Tools.parserJSONArray(headersJsonArr);
		if(jsonArr!=null)
		{
			int len = jsonArr.length();
			if(len>0)
			{
				headers = new HashMap<String, String>();
				JSONObject jsonObj;
				for(int i=0;i<len;i++) {
					jsonObj = jsonArr.optJSONObject(i);
					if(jsonObj!=null)
					{
						try {
							headers.put(jsonObj.optString("name"),jsonObj.optString("value"));
						} catch(UnsupportedOperationException e) {
							
						} catch(ClassCastException e) {
							
						} catch(IllegalArgumentException e) {
							
						} catch(NullPointerException e) {
							
						}
					}
				}
			}
		}
		return headers;
	}
	
	private void addUrl(String url,Map<String, String> headers) {
		if(url!=null&&url.length()>0)
		{
			if(urlInfoList==null)
			{
				urlInfoList = new ArrayList<UrlInfo>();
			}
			if(urlInfoList.size()==0||!url.equals(urlInfoList.get(urlInfoList.size()-1).getUrl()))
			{
				UrlInfo info = new UrlInfo();
				info.setUrl(url);
				info.setHeaders(getHeadersJSONArray(headers));
				urlInfoList.add(info);
			}
		}
	}
	
	public void loadUrlInfo(UrlInfo info) {
		if(info!=null)
		{
			String url = info.getUrl();
			String getData = info.getGetData();
			String headers = info.getHeaders();
			int cacheType = info.getCacheType();
			String savePath = info.getSavePath();
			if(url!=null&&url.length()>0)
			{
				if(getData!=null&&getData.length()>0)
				{
					if(!getData.startsWith("?"))
					{
						getData = "?"+getData;
					}
					url += getData;
				}
				if(cacheType==1)//优先使用本地缓存
				{
					String filePath = Tools.getExistsFilePath(mContext, savePath);
					if(filePath!=null&&filePath.length()>0) {
						url = "file://"+filePath;
						if(getData!=null&&getData.length()>0)
						{
							url += getData;
						}
						loadUrl(url,getHeadersMap(headers));
					}
					else
					{
						
						//开启线程下载
						loadUrl(url,getHeadersMap(headers));
					}
				}
				else if(cacheType==2)//只有当前无网络时使用本地缓存
				{
					if(SystemInfo.isNetworkAvailable(mContext))//当前网络可用
					{
						//开启线程下载
						loadUrl(url,getHeadersMap(headers));
					}
					else
					{
						String filePath = Tools.getExistsFilePath(mContext, savePath);
						if(filePath!=null&&filePath.length()>0) {
							url = "file://"+filePath;
							if(getData!=null&&getData.length()>0)
							{
								url += getData;
							}
							loadUrl(url,getHeadersMap(headers));
						}
						else
						{
							//开启线程下载
							loadUrl(url,getHeadersMap(headers));
						}
					}
				}
				else//不使用缓存
				{
					loadUrl(url,getHeadersMap(headers));
				}
			}
		}
	}
	
	/**
	 * 加载URL地址
	 * @param url
	 */
	public void loadUrl(String url) {
		if(url!=null&&url.length()>0)
		{
			addUrl(url,null);
			if(!url.equals(DEFAULT_URL_BLANK))
			{
				mWebView.loadUrl(url);
			}
			else
			{
				mWebView.loadData(defaultData,defaultMimeType,defaultEncoding);
			}
		}
	}
	
	/**
	 * 加载URL地址,同时指定上传头信息
	 * @param url
	 * @param headers
	 */
	public void loadUrl(String url, Map<String, String> headers) {
		if(url!=null&&url.length()>0)
		{
			addUrl(url,headers);
			if(!url.equals(DEFAULT_URL_BLANK))
			{
				mWebView.loadUrl(url,headers);
			}
			else
			{
				mWebView.loadData(defaultData,defaultMimeType,defaultEncoding);
			}
		}
	}
	
	/**
	 * 加载HTML页面数据
	 * @param data
	 * @param mimeType
	 * @param encoding
	 */
	public void loadData(String data, String mimeType, String encoding) {
		if(data!=null&&data.length()>0)
		{
			if(mimeType==null||mimeType.length()==0)
			{
				mimeType="text/html";
			}
			if(encoding==null||encoding.length()==0)
			{
				encoding="UTF-8";
			}
			addUrl(DEFAULT_URL_BLANK,null);
			defaultData = data;
			defaultMimeType = mimeType;
			defaultEncoding = encoding;
			mWebView.loadData(data, mimeType, encoding);
		}
	}
	
	public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl) {
		if(data!=null&&data.length()>0)
		{
			if(mimeType==null||mimeType.length()==0)
			{
				mimeType="text/html";
			}
			if(encoding==null||encoding.length()==0)
			{
				encoding="UTF-8";
			}
			addUrl(baseUrl,null);
			defaultData = data;
			defaultMimeType = mimeType;
			defaultEncoding = encoding;
			mWebView.loadDataWithBaseURL(baseUrl,data,mimeType,encoding,historyUrl);
		}
	}
	
	/**
	 * 加载任意JavaScript代码
	 * @param javaScriptString
	 */
	public void loadJavaScript(String javaScriptString) {
		Tools.showLog("muge", "loadJavaScript() javaScriptString="+javaScriptString);
		if(javaScriptString!=null&&javaScriptString.length()>0)
		{
			mWebView.loadUrl(javaScriptString);
		}
	}
	
	/**
	 * 加载JavaScript方法
	 * @param javaScriptFunction
	 */
	public void loadJavaScriptFunction(String javaScriptFunction) {
		Tools.showLog("muge", "loadJavaScriptFunction() javaScriptFunction="+javaScriptFunction);
		if(javaScriptFunction!=null&&javaScriptFunction.length()>0)
		{
			String javaScriptString = "javascript:" + javaScriptFunction;
			loadJavaScript(javaScriptString);
		}
	}
	
	/**
	 * 隐藏缩放按钮
	 * @param view
	 */
	private void setZoomControlGone(View view) {  
	    Class classType;  
	    Field field;
	    try {  
	        classType = WebView.class;  
	        field = classType.getDeclaredField("mZoomButtonsController");  
	        field.setAccessible(true);  
	        ZoomButtonsController mZoomButtonsController = new ZoomButtonsController(view);  
	        mZoomButtonsController.getZoomControls().setVisibility(View.GONE);  
	        try {  
	            field.set(view, mZoomButtonsController);  
	        } catch (IllegalArgumentException e) {  
	            e.printStackTrace();  
	        } catch (IllegalAccessException e) {  
	            e.printStackTrace();  
	        }  
	    } catch (SecurityException e) {  
	        e.printStackTrace();  
	    } catch (NoSuchFieldException e) {  
	        e.printStackTrace();  
	    }  
	}
	
	/**
	 * 滑动到页面顶端
	 */
	private void onScrollTopAction() {
		Tools.showLog("muge", "onScrollTopAction 滑动到最頂端！");
		loadJavaScriptFunction("onScrollTop()");
    }
    
	/**
	 * 滑动到页面最底端
	 */
    private void onScrollBottomAction() {
    	Tools.showLog("muge", "onScrollBottomAction 滑动到最底端！");
    	loadJavaScriptFunction("onScrollBottom()");
    }
    
    /**
	 * 滑动到页面最左端
	 */
	private void onScrollLeftAction() {
		Tools.showLog("muge", "onScrollLeftAction 滑动到最左端！");
		loadJavaScriptFunction("onScrollLeft()");
    }
    
	/**
	 * 滑动到页面最右端
	 */
    private void onScrollRightAction() {
    	Tools.showLog("muge", "onScrollRightAction 滑动到最右端！");
    	loadJavaScriptFunction("onScrollRight()");
    }
    
    public void setOnLoadProgressListener(OnLoadProgressListener listener) {
    	loadProgressListener = listener;
    }
    
    /**
     * 绑定自定义WebChromeClient
     * @param listener
     */
    public void setWebChromeClient(WebChromeClient client) {
    	mWebView.setWebChromeClient(client);
    }
	
    /**
     * 默认浏览器交互处理客户端
     */
	private final WebChromeClient defaultWebChromeClient = new WebChromeClient() {
        
        @Override
        public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
        	Tools.showLog("muge", "WebChromeClient.onJsAlert() url="+url+" message="+message);
        	return false;
        }
        
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
        	Tools.showLog("muge", "WebChromeClient.onProgressChanged() newProgress="+newProgress+"%");
        	if(loadProgressListener!=null)
        	{
        		loadProgressListener.onProgressChanged(newProgress);
        	}
        }
        
	};
	
	/**
     * 绑定自定义WebViewClient
     * @param listener
     */
    public void setWebViewClient(WebViewClient client) {
    	mWebView.setWebViewClient(client);
    }
	
	/**
	 * 默认WebView页面加载客户端
	 */
	private final WebViewClient defaultWebViewClient = new WebViewClient() {
		
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
        	Tools.showLog("muge", "WebViewClient.shouldOverrideUrlLoading() url="+url);
        	return false;
        }
        
        @Override
        public void onPageFinished(WebView view, String url) {
        	Tools.showLog("muge", "WebViewClient.onPageFinished() url="+url);
        	if(loadProgressListener!=null)
        	{
        		loadProgressListener.onPageFinished(url);
        	}
        	loadJavaScriptFunction("onPageFinished('"+url+"')");
        }
        
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
        	Tools.showLog("muge", "WebViewClient.onPageStarted() url="+url);
        	if(loadProgressListener!=null)
        	{
        		loadProgressListener.onPageStarted(url);
        	}
        }
        
    };
    
    /**
     * 绑定自定义点击事件监听接口
     * @param listener
     */
    public void setOnClickListener(OnClickListener listener) {
    	mWebView.setOnClickListener(listener);
    }
    
    /**
     * 默认点击事件监听接口
     */
    private final OnClickListener defaultOnClickListener = new OnClickListener() {

		@Override
		public void onClick(View arg0) {
			Tools.showLog("muge", "OnClickListener.onClick()");
		}
    	
    };
    
    /**
     * 绑定自定义长按事件监听接口
     * @param listener
     */
    public void setOnLongClickListener(OnLongClickListener listener) {
    	mWebView.setOnLongClickListener(listener);
    }
    
    /**
     * 默认长按事件监听接口
     */
    private final OnLongClickListener defaultOnLongClickListener = new OnLongClickListener() {

		@Override
		public boolean onLongClick(View v) {
			Tools.showLog("muge", "OnLongClickListener.onLongClick()");
			return false;
		}
    	
    };
    
    /**
     * 绑定自定义长按菜单弹出事件监听接口
     * @param listener
     */
    public void setOnCreateContextMenuListener(OnCreateContextMenuListener listener) {
    	mWebView.setOnCreateContextMenuListener(listener);
    }
    
    /**
     * 默认长按菜单弹出事件监听接口
     */
    private final OnCreateContextMenuListener defaultOnCreateContextMenuListener = new OnCreateContextMenuListener() {

		@Override
		public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
			Tools.showLog("muge", "OnCreateContextMenuListener.onCreateContextMenu()");
		}
    	
    };
    
    /**
     * 绑定自定义光标状态变化事件监听接口
     * @param listener
     */
    public void setOnFocusChangeListener(OnFocusChangeListener listener) {
    	mWebView.setOnFocusChangeListener(listener);
    }
    
    /**
     * 默认光标状态变化事件监听接口
     */
    private final OnFocusChangeListener defaultOnFocusChangeListener = new OnFocusChangeListener() {

		@Override
		public void onFocusChange(View v, boolean hasFocus) {
			Tools.showLog("muge", "OnFocusChangeListener.onFocusChange()");
		}
    	
    };
    
    /**
     * 绑定自定义层次变化事件监听接口
     * @param listener
     */
    public void setOnHierarchyChangeListener(OnHierarchyChangeListener listener) {
    	mWebView.setOnHierarchyChangeListener(listener);
    }
    
    /**
     * 默认层次变化事件监听接口
     */
    private final OnHierarchyChangeListener defaultOnHierarchyChangeListener = new OnHierarchyChangeListener() {

		@Override
		public void onChildViewAdded(View parent, View child) {
			Tools.showLog("muge", "OnHierarchyChangeListener.onChildViewAdded()");
		}

		@Override
		public void onChildViewRemoved(View parent, View child) {
			Tools.showLog("muge", "OnHierarchyChangeListener.onChildViewRemoved()");
		}
    	
    };
    
    /**
     * 绑定自定义触屏事件监听接口
     * @param listener
     */
    public void setOnTouchListener(OnTouchListener listener) {
    	mWebView.setOnTouchListener(listener);
    }
    
    /**
     * 默认触屏事件监听接口
     */
    private final OnTouchListener defaultOnTouchListener = new OnTouchListener() {

		@Override
		public boolean onTouch(View arg0, MotionEvent arg1) {
			Tools.showLog("muge", "OnTouchListener.onTouch() getX="+arg1.getX()+" getY="+arg1.getY());
			return false;
		}
    	
    };
	
    /**
     * 绑定自定义按键事件监听接口
     * @param listener
     */
    public void setOnKeyListener(OnKeyListener listener) {
    	mWebView.setOnKeyListener(listener);
    }
    
    /**
     * 默认按键事件监听接口
     */
    private final OnKeyListener defaultOnKeyListener = new OnKeyListener() {
		
		@Override
		public boolean onKey(View v, int keyCode, KeyEvent event) {
			Tools.showLog("muge", "OnKeyListener.onKey() keyCode="+keyCode);
			if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN)// 按下返回键
            {
                return false;
            }
            return false;
		}

    };
    
    /**
     * 绑定自定义滑动事件监听接口
     * @param listener
     */
    public void setOnScrollChangedListener(OnScrollChangedListener listener) {
    	mWebView.setOnScrollChangeListener(listener);
    }
    
    /**
     * 默认滑动事件监听接口
     */
    private final OnScrollChangedListener defaultOnScrollChangedListener = new OnScrollChangedListener() {

		@Override
		public void onScrollChanged(int l, int t, int oldl, int oldt) {
			//Tools.showLog("muge", "OnScrollChangedListener.onScrollChanged() VerticalScrollLeftDistance="+mWebView.getVerticalScrollLeftDistance()+" HorizontalScrollLeftDistance"+mWebView.getHorizontalScrollLeftDistance()+" l="+l+" t="+t+" oldl="+oldl+" oldt="+oldt);
		}

		private long lastOnScrollTopTime;
		@Override
		public void onScrollTop(int l, int t, int oldl, int oldt) {
			long currentTime = System.currentTimeMillis();
			if(lastOnScrollTopTime<=0||(currentTime-lastOnScrollTopTime)>=1000)
			{
				lastOnScrollTopTime = currentTime;
				onScrollTopAction();
			}
		}

		private long lastOnScrollBottomTime;
		@Override
		public void onScrollBottom(int l, int t, int oldl, int oldt) {
			long currentTime = System.currentTimeMillis();
			if(lastOnScrollBottomTime<=0||(currentTime-lastOnScrollBottomTime)>=1000)
			{
				lastOnScrollBottomTime = currentTime;
				onScrollBottomAction();
			}
		}
		
		private long lastOnScrollLeftTime;
		@Override
		public void onScrollLeft(int l, int t, int oldl, int oldt) {
			//Tools.showLog("muge", "OnScrollChangedListener.onScrollLeft()");
			long currentTime = System.currentTimeMillis();
			if(lastOnScrollLeftTime<=0||(currentTime-lastOnScrollLeftTime)>=1000)
			{
				lastOnScrollLeftTime = currentTime;
				onScrollLeftAction();
			}
		}
		
		private long lastOnScrollRightTime;
		@Override
		public void onScrollRight(int l, int t, int oldl, int oldt) {
			//Tools.showLog("muge", "OnScrollChangedListener.onScrollRight()");
			long currentTime = System.currentTimeMillis();
			if(lastOnScrollRightTime<=0||(currentTime-lastOnScrollRightTime)>=1000)
			{
				lastOnScrollRightTime = currentTime;
				onScrollRightAction();
			}
		}
    	
    };
    
    public String doMyActionString(String jsonInfo) {
    	return WebViewControl.getInstance(mContext).doMyActionString(jsonInfo);
    }
    
    /**
     * 绑定自定义Javascript交互接口
     * @param javascriptInterface
     * @param name
     */
    public void addJavascriptInterface(Object javascriptInterface,String name) {
    	mWebView.addJavascriptInterface(javascriptInterface, name);
    }
    
    
    private int testCount = 0;
    /**
     * 默认Javascript交互接口
     */
    private final Object defaultJavascriptInterface = new JavascriptInterface ()  {
    	
    	@JavascriptInterface
    	public String doActionString(String jsonInfo){
    		testCount++;
			Tools.showLog("muge", "doActionString() jsonInfo="+jsonInfo+"  testCount = "+testCount);
			//return doMyActionString(jsonInfo);
			//return "abc"+
			if(testCount==1)
			{
				return "true";
			}
			else if(testCount==2)
			{
				return "false";
			}
			else if(testCount==3)
			{
				return "1";
			}
			else if(testCount==4)
			{
				return "10000";
			}
			else if(testCount==5)
			{
				return "adc";
			}
			else if(testCount==6)
			{
				return "";
			}
			else if(testCount==7)
			{
				return null;
			}
			else
			{
				return "adc"+(int)(Math.random()*100);
			}
		}

		@Override
		public Class<? extends Annotation> annotationType() {
			// TODO Auto-generated method stub
			return null;
		}
		
    };
    
    
    /*
    public class MJavascriptInterface implements JavascriptInterface () {
    	
    	@JavascriptInterface
    	public boolean doActionBoolean(String jsonArr){
			Tools.showLog("muge", "doActionBoolean() action="+jsonArr);
			return false;
		}
    	
    	public String doActionStr(String jsonArr){
			Tools.showLog("muge", "doActionStr() action="+jsonArr);
			return "返回值成功！";
		}
		
		public void doActionList(String jsonArr){
			Tools.showLog("muge", "doActionList() action="+jsonArr);
		}
		
		public void doAction(String jsonObj){
			Tools.showLog("muge", "doAction() action="+jsonObj);
		}
		
		public void doActionSimple(String action){
			Tools.showLog("muge", "doActionSimple() action="+action);
		}

	};
	**/
}